﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace AgriMarketService
{
    /// <summary>
    /// Summary description for AgriMarketWebService
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class AgriMarketWebService : System.Web.Services.WebService
    {
        #region Articles
        [WebMethod(Description = "Get an article by articleId")]
        public Article GetAnArticleByArticleId(int articleId)
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.GetAnArticleByArticleId(articleId);
        }
        [WebMethod(Description = "Get all recent SellBuyArticles")]
        public List<Article> GetAllNewArticles()
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.GetNewArticles();
        }
        [WebMethod(Description = "Get all recent SellArticles")]
        public List<Article> GetAllNewSellArticles()
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.GetNewSellArticles();
        }
        [WebMethod(Description = "Get COUNT SellArticles whose articleIds are greater than STARTEDID if ISLESS is false")]
        public List<Article> GetNewSellArticles(int startedId, int count, bool isLess)
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.GetNewSellArticles(startedId, count, isLess);
        }
        [WebMethod(Description = "Get COUNT New SellAritcles")]
        public List<Article> DisplayNNewSellArticles(int count)
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.GetNNewSellArticles(count);
        }
        [WebMethod(Description = "Get COUNT New BuyAritcles")]
        public List<Article> DisplayNNewBuyArticles(int count)
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.GetNNewBuyArticles(count);
        }
        [WebMethod(Description = "Get All New BuyAritcles")]
        public List<Article> GetAllNewBuyArticles()
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.GetNewBuyArticles();
        }
        [WebMethod(Description = "Get COUNT BuyArticles whose articleIds are greater than STARTEDID if ISLESS is false")]
        public List<Article> GetNewBuyArticles(int startedId, int count, bool isLess = true)
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.GetNewBuyArticles(startedId, count, isLess);
        }
        [WebMethod(Description = "Add a New Article")]
        public int AddNewArticle(Article newArticle)
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.AddArticle(newArticle);
        }
        [WebMethod(Description = "Update a specified Article")]
        public int UpdateArticle(Article updatedArticle)
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.UpdateArticle(updatedArticle);
        }
        [WebMethod(Description = "Delete an Article by Id")]
        public int DeleteArticleByArticleId(int deletedArticleId)
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.DeleteArticleByArticleId(deletedArticleId);
        }
        #endregion
        #region Comments
        [WebMethod(Description = "Get all comment of a specified article by articleId")]
        public List<ArticleComment> GetAllArticleCommentsByArticleId(int articleId)
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.DisplayAllArticleCommentsByArticleId(articleId);
        }
        [WebMethod(Description = "Add a new comment")]
        public int AddCommentToArticle(ArticleComment newArticleComment)
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.AddCommentToArticle(newArticleComment);
        }
        [WebMethod(Description = "Update a specified comment")]
        public int UpdateComment(ArticleComment updatedComment)
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.UpdateComment(updatedComment);
        }
        [WebMethod(Description = "Delete a specified comment by articleId")]
        public int DeleteArticleCommentByArticleCommentId(int deletedArticleCommentId)
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.DeleteArticleCommentByArticleCommentId(deletedArticleCommentId);
        }
        [WebMethod(Description = "Delete all comments of a article specified by articleId")]
        public bool DeleteAllArticleCommentsByArticleId(int articleId)
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.DeleteAllArticleCommentsByArticleId(articleId);
        }
        [WebMethod(Description = "Get COUNT next comments of a article specified by articleId")]
        public List<ArticleComment> GetNNextArticleComments(int articleId, int startedArticleCommentId, int count)
        {
            AgriMarket agriMarket = new AgriMarket();
            AgriMarketDataClassesDataContext db = new AgriMarketDataClassesDataContext();
            return agriMarket.DisplayNNextArticleComments(articleId, startedArticleCommentId, count);
        }
        #endregion
        #region UserAndUserAccount
        [WebMethod(Description = "Check LogIn by passing username and password")]
        public bool CheckLogIn(string userName, string password)
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.CheckLogIn(userName, password);
        }
        [WebMethod(Description = "Get useraccount by username")]
        public UserAccount GetUserAccountByUserName(string userName)
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.GetUserAccountByUserName(userName);
        }
        [WebMethod(Description = "Get user by userid")]
        public User GetUserByUserId(int userId)
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.GetUserByUserId(userId);
        }
        [WebMethod(Description = "Get image of userAcc")]
        public string GetUserImage(string userAccName)
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.GetUserImage(userAccName);
        }
        #endregion
        #region Auctions
        [WebMethod(Description = "Get n new unfinished auctions")]
        public List<Auction> GetNNewUnfinishedAuctions(int n)
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.GetNNewUnfinishedAuctions(n);
        }
        [WebMethod(Description = "Get N auctions whose auctionIds are greater than STARTEDID if ISLESS is false")]
        public List<Auction> GetNNextUnfinishedAuctions(int startedId, int count, bool isLess)
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.GetNNextUnfinishedAuctions(startedId, count, isLess);
        }
        [WebMethod(Description = "Get all new being auctions")]
        public List<Auction> GetBeingAuctions()
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.GetBeingAuctions();
        }
        [WebMethod(Description = "Get n first being auctions")]
        public List<Auction> GetNFirstBeingAuctions(int n)
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.GetNFirstBeingAuctions(n);
        }
        [WebMethod(Description = "Get N being auctions whose auctionIds are greater than STARTEDID if ISLESS is false")]
        public List<Auction> GetNNextBeingAuctions(int startedId, int count, bool isLess)
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.GetNNextBeingAuctions(startedId, count, isLess);
        }
        [WebMethod(Description = "Get all unfinished buyauctions")]
        public List<Auction> GetAllUnfinishedBuyAuctions()
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.GetAllUnfinishedBuyAuctions();
        }
        [WebMethod(Description = "Get N new buyauctions")]
        public List<Auction> GetNNewUnFinishedBuyAuctions(int n)
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.GetNNewUnfinishedBuyAuctions(n);
        }
        [WebMethod(Description = "Get N buyauctions whose auctionIds are greater than STARTEDID if ISLESS is false")]
        public List<Auction> GetNUnfinishedBuyAuctions(int startedId, int n, bool isLess)
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.GetNUnfinishedBuyAuctions(startedId, n, isLess);
        }
        [WebMethod(Description = "Add a new auction")]
        public int AddNewAuction(Auction newAuction)
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.AddNewAuction(newAuction);
        }
        [WebMethod(Description = "Update a new auction")]
        public int UpdateAuction(Auction updatedAuction)
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.UpdateAuction(updatedAuction);
        }
        [WebMethod(Description = "Delete an auction by Id")]
        public int DeleteAuction(int deletedAuctionId)
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.DeleteAuction(deletedAuctionId);
        }
        [WebMethod(Description = "Get N New Auctioneers")]
        public List<Auctioneer> GetNNNewAuctioneers(int auctionId, int n)
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.GetNNewAuctioneers(auctionId, n);
        }
        [WebMethod(Description = "Get N Next Auctioneers whose auctioneerId is greater than startedAuctioneerId when isOld is true")]
        public List<Auctioneer> GetNNextAuctioneers(int auctionId, int startedAuctioneerId, int n, bool isNew)
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.GetNNextAuctioneers(auctionId,startedAuctioneerId, n,isNew);
        }
        [WebMethod(Description = "Add new auctioneer and return auctioneerId (-1 for failure)")]
        public int AddNewAuctioneer(Auctioneer newAuctioneer)
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.AddNewAuctioneer(newAuctioneer);
        }
        [WebMethod(Description = "Get Highest Price of auction has auctionId")]
        public decimal GetHighestPrice(int auctionId)
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.GetHighestPrice(auctionId);
        }
        [WebMethod(Description = "Get all type of auction")]
        public List<TypeOfAuction> GetAllTypeOfAuction()
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.GetAllTypeOfAuction();
        }
        [WebMethod(Description = "Get auction by id")]
        public Auction GetAuctionById(int auctionId)
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.GetAuctionById(auctionId);
        }

        [WebMethod(Description = "Get N new sellauctions")]
        public List<Auction> GetNNewUnFinishedSellAuctions(int n)
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.GetNNewUnfinishedSellAuctions(n);
        }
        [WebMethod(Description = "Get N sellauctions whose auctionIds are greater than STARTEDID if ISLESS is false")]
        public List<Auction> GetNUnfinishedSellAuctions(int startedId, int n, bool isLess)
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.GetNUnfinishedSellAuctions(startedId, n, isLess);
        }
        [WebMethod(Description = "Get lowest Price of auction has auctionId")]
        public decimal GetLowestPrice(int auctionId)
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.GetLowestPrice(auctionId);
        }
        [WebMethod(Description = "Search for aution")]
        public List<Auction> SearchForAuctions(string content)
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.SearchForAuction(content);
        }
        [WebMethod(Description = "Get All auctioneers")]
        public List<Auctioneer> GetAllAuctioneers()
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.GetAllAuctioneers();
        }
        [WebMethod(Description = "Get All auctioneer by id")]
        public Auctioneer GetAuctioneerById(int auctioneerId)
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.GetAuctioneerById(auctioneerId);
        }
        [WebMethod(Description = "Delete Auctioneer by id")]
        public bool DeleteAuctioneerById(int auctioneerId)
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.DeleteAuctioneerById(auctioneerId);
        }
        [WebMethod(Description = "Update auctioneer")]
        public int UpdateAuctioneer(Auctioneer updatedAuctioneer)
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.UpdateAuctioneer(updatedAuctioneer);
        }
        [WebMethod(Description = "Get all being buyAuctions")]
        public List<Auction> GetBeingBuyAuctions()
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.GetBeingBuyAuctions();
        }
        [WebMethod(Description = "Get all being sellAuctions")]
        public List<Auction> GetBeingSellAuctions()
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.GetBeingSellAuctions();
        }
        [WebMethod(Description = "Get n first being buyAuction")]
        public List<Auction> GetNFirstBeingBuyAuctions(int n)
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.GetNFirstBeingBuyAuctions(n);
        }
        [WebMethod(Description = "Get n first being sellAuction")]
        public List<Auction> GetNFirstBeingSellAuctions(int n)
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.GetNFirstBeingSellAuctions(n);
        }
        [WebMethod(Description = "Get n next being buyAuction")]
        public List<Auction> GetNNextBeingBuyAuctions(int startedId, int count, bool isLess)
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.GetNNextBeingBuyAuctions(startedId, count, isLess);
        }
        [WebMethod(Description = "Get n next being sellAuction")]
        public List<Auction> GetNNextBeingSellAuctions(int startedId, int count, bool isLess)
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.GetNNextBeingSellAuctions(startedId, count, isLess);
        }
        #endregion
        #region File
        [WebMethod(Description = "Upload")]
        public bool Upload(byte[] file, string name)
        {
            return FileProvider.Upload(file, name);
        }
        #endregion
        #region Types
        [WebMethod(Description = "Get all types of article")]
        public List<TypeOfArticle> GetAllTypesOfArticle()
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.GetAllTypesOfArticle();
        }
        [WebMethod(Description = "Get types of article by type of articleId")]
        public TypeOfArticle GetTypeOfArticlesById(int typeOfArticleId)
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.GetTypeOfArticlesById(typeOfArticleId);
        }

        [WebMethod(Description = "Get all types of auction")]
        public List<TypeOfAuction> GetAllTypesOfAuction()
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.GetAllTypesOfAuction();
        }
        [WebMethod(Description = "Get types of auction by type of auctionId")]
        public TypeOfAuction GetTypeOfAuctionById(int typeOfAuctionId)
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.GetTypeOfAuctionById(typeOfAuctionId);
        }
        [WebMethod(Description = "Update types of auction")]
        public int UpdateTypeOfAuction(TypeOfAuction updatedAuction)
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.UpdateTypeOfAuction(updatedAuction);
        }
        [WebMethod(Description = "Delete types of auction by id")]
        public int DeleteTypeOfAuctionById(int typeId)
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.DeleteTypeOfAuctionById(typeId);
        }
        [WebMethod(Description = "Add new types of auction")]
        public int AddNewTypeOfAuction(TypeOfAuction newType)
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.AddNewTypeOfAuction(newType);
        }
        [WebMethod(Description = "Get all types of product")]
        public List<TypeOfProduct> GetAllTypesOfProduct()
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.GetAllTypesOfProduct();
        }
        [WebMethod(Description = "Get types of product by type of productId")]
        public TypeOfProduct GetTypeOfProductById(int typeOfProductId)
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.GetTypeOfProductById(typeOfProductId);
        }
        [WebMethod(Description = "Get all unis")]
        public List<Unit> GetAllUnits()
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.GetAllUnits();
        }
        [WebMethod(Description = "Get units by type of unitId")]
        public Unit GetUnitById(int unitId)
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.GetUnitById(unitId);
        }
        #endregion
        #region Product
        [WebMethod(Description = "Get product by productId")]
        public  Product GetProductById(int productId)
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.GetProductById(productId);
        }
        [WebMethod(Description = "Get all products")]
        public  List<Product> GetAllProducts()
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.GetAllProducts();
        }
        #endregion
        #region FollowedAuction
        [WebMethod(Description = "Get FollowedAuctions By UserAccName")]
        public List<FollowedAuction> GetFollowedAuctionsByUserAccName(string userAccName)
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.GetFollowedAuctionsByUserAccName(userAccName);
        }
        [WebMethod(Description = "Add new FollowedAuctions")]
        public int AddNewFollowedAuction(string userAccName, int auctionId)
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.AddNewFollowedAuction(userAccName,auctionId);
        }
        [WebMethod(Description = "Delete followedAuction")]
        public int DeleteFollowedAuction(int deletedFaID)
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.DeleteFollowedAuction(deletedFaID);
        }
        [WebMethod(Description = "Get a followedAuction by id")]
        public FollowedAuction GetAFollowedAuctionById(int followedAuctionId)
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.GetAFollowedAuctionById(followedAuctionId);
        }
        [WebMethod(Description = "Delete all followedAuctions of auction by auctionId")]
        public bool DeleteFollowedAuctionsByAuctionId(int auctionId)
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.DeleteFollowedAuctionsByAuctionId(auctionId);
        }
        #endregion
        #region Statistic
        [WebMethod(Description = "Get Year Statistic for product")]
        public List<YProduct> GetYearStatistic(int year)
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.GetYearStatistic(year);
        }
        [WebMethod(Description = "Get Year Statistic for product from start year and finish year")]
        public List<YProduct> GetYearStatisticInDuration(int start, int finish) 
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.GetYearStatisticInDuration(start,finish);
        }
        #endregion
        #region Send Email
        [WebMethod(Description = "Send Email To All Winner")]
        public bool SendEmailToAllWinners() {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.SendEmailToAllWinners();
        }
        [WebMethod(Description = "Send Email To A Winner")]
        public int SendEmailtoAWinner(int auctionId)
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.SendEmailtoAWinner(auctionId);
        }
        [WebMethod(Description = "Send Email To List Winners")]
        public List<int> SendEmailtoSomeWinners(List<int> auctionIds)
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.SendEmailtoSomeWinners(auctionIds);
        }
        [WebMethod(Description = "Get unsent auctions")]
        public List<Auction> GetUnSentAuctions()
        {
            AgriMarket agriMarket = new AgriMarket();
            return agriMarket.GetUnSentAuctions();
        }
        #endregion
    }
}
